package servlet.login;

import com.alibaba.fastjson.JSONObject;
import service.UserLoginService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updateuser")
public class UpdateUser extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 设置响应内容类型
        resp.setContentType("text/html;charset=UTF-8");

        // 获取表单数据
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String phone = req.getParameter("phone");
        String email = req.getParameter("email");
        String address = req.getParameter("address");

        // 在这里执行其他逻辑，例如保存表单数据到数据库等
        UserLoginService userLoginService = new UserLoginService();
        int i = userLoginService.updateUser(username, password, phone, email, address);
        JSONObject jsonResponse = new JSONObject();
        if (i==1){
            System.out.println("修改用户信息成功");
            jsonResponse.put("code",1);
            resp.getWriter().println(jsonResponse.toJSONString());
        }else {
            System.out.println("修改用户信息失败");
            jsonResponse.put("code",0);
            resp.getWriter().println(jsonResponse.toJSONString());
        }
    }
}
